import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })

import NotFound from '@/views/NotFound.vue'

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
    {
        path: '/',
        redirect: { name: 'home' },
    },
    {
        path: '/home',
        name: 'home',
        component: () => import(/* webpackChunkName: "home" */ '../views/HomeView.vue'),
    },
    {
        path: '/about',
        name: 'about',
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
    },
    {
        path: '/synthesis',
        name: 'synthesis',
        component: () => import(/* webpackChunkName: "synthesis" */ '../views/SynthesisView.vue'),
    },
    {
        path: '/products',
        name: 'products',
        component: () => import(/* webpackChunkName: "products" */ '../views/ProductView.vue'),
    },
    {
        path: '/product-search',
        name: 'product-search',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductSearch.vue'),
    },
    {
        path: '/standards',
        name: 'standards',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/StandardList.vue'),
    },
    {
        path: '/project',
        name: 'project',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProjectList.vue'),
    },
    {
        path: '/stock',
        name: 'stock',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/StockList.vue'),
    },
    {
        path: '/brand',
        name: 'brand',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/BrandList.vue'),
    },
    {
        path: '/product-detail',
        name: 'product-detail',
        meta: {
            parent: 'products',
        },
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductDetail.vue'),
    },
    {
        path: '/news',
        name: 'news',
        component: () => import(/* webpackChunkName: "news" */ '../views/NewsView.vue'),
    },
    {
        path: '/news-search',
        name: 'news-search',
        meta: {
            parent: 'news',
        },
        component: () => import(/* webpackChunkName: "news" */ '../views/news/NewsSearch.vue'),
    },
    {
        path: '/news-detail',
        name: 'news-detail',
        meta: {
            parent: 'news',
        },
        component: () => import(/* webpackChunkName: "news" */ '../views/news/NewsDetail.vue'),
    },
    {
        path: '/jobs',
        name: 'jobs',
        component: () => import(/* webpackChunkName: "jobs" */ '../views/JobView.vue'),
    },
    {
        path: '/contact',
        name: 'contact',
        component: () => import(/* webpackChunkName: "contact" */ '../views/ContactView.vue'),
    },
    {
        path: '*',
        component: NotFound,
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
})

router.beforeEach((to, from, next) => {
    NProgress.start()
    next()
})
router.afterEach(() => {
    NProgress.done()
})

export default router
